package com.zm.zb100.service;

import com.zm.zb100.persistence.entity.db.Demo;
import com.zm.zb100.repository.DemoRepository;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Demo0
 *
 * <p>
 * </p>
 *
 * @author chuanbai
 * @date 2024/9/30
 */
@Component
public class Demo0 {

    @Resource
    private DemoRepository demoRepository;


    /**
     * 内层事务
     */
    @Transactional
    public String innerInsert(){
        try {
            Demo demo = new Demo();
//        demo.setLogisticsNo("1Z24X7196650022101");
            demo.setLogisticsNo("innerInsert");
            Demo save = demoRepository.save(demo);

//            int i = 10 / 0;

            System.out.println("innerInsert   end------>");
            return "innerInsert ok";
        }catch (Exception e){
            System.out.println("innerInsert error.");
            throw new RuntimeException("innerInsert error", e); // 显式抛出运行时异常
        }
    }
}
